package com.example.woke1;

import java.util.ArrayList;

import cn.xl.xxl.imagecache.ImageLoader;

import com.zhongcai.online.R;
import com.topnews.view.imageshow.ImageShowViewPager;
import com.woke.adapter.ImagePagerAdapter;

import android.os.Bundle;
import android.app.Activity;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

public class ImageShowActivity extends Activity {

	/** ͼƬչʾ */
	private ImageShowViewPager image_pager;
	private TextView page_number;
	/** ͼƬ���ذ�ť */
	private ImageView download;
	/** ͼƬ�б� */
	private ArrayList<String> imgsUrl;
	/** PagerAdapter */
	private ImagePagerAdapter mAdapter;
	private int cuuuu;
	private String index;
	private ImageLoader imageLoader;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.details_imageshow);
		
		imageLoader = new ImageLoader(this);
		initView();
	}
	
	@Override
	protected void onDestroy() {
		imageLoader.clearCache();
		imageLoader.clearMemoryCache();
		super.onDestroy();
	}

	private void initData() {
		cuuuu = 0;
		index = getIntent().getStringExtra("index");
		imgsUrl = getIntent().getStringArrayListExtra("infos");
//		String iconrul = getIntent().getStringExtra("iconrul");
		Log.i("cuuuu", "��ǣ�"+imgsUrl);
		for(int i =0; i < imgsUrl.size(); ++i){
		if(imgsUrl.get(i).equals(index)){
		  //iΪ��元���������е�λ��
			 cuuuu = i;
		}
		page_number.setText(""+cuuuu+1 + "/" + imgsUrl.size());
	}
		
		initViewPager();
	}
	@Override
	public void onResume() {
		super.onResume();
	}

	@Override
	public void onPause() {
		super.onPause();
	}

	private void initView() {
		image_pager = (ImageShowViewPager) findViewById(R.id.image_pager);
		page_number = (TextView) findViewById(R.id.page_number);
		download = (ImageView) findViewById(R.id.download);
		image_pager.setOnPageChangeListener(new OnPageChangeListener() {
			
			@Override
			public void onPageSelected(int arg0) {
				page_number.setText((arg0 + 1) + "/" + imgsUrl.size());
			}
			
			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub
				
			}
		});
		initData();
		
	}

	private void initViewPager() {
		if (imgsUrl != null && imgsUrl.size() != 0) {
			mAdapter = new ImagePagerAdapter(ImageShowActivity.this, imgsUrl,imageLoader);
			image_pager.setAdapter(mAdapter);
			image_pager.setOffscreenPageLimit(0);
			image_pager.setCurrentItem(cuuuu);
		}
	}

}
